using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

[RequireComponent(typeof(CanvasGroup))]
public class UIBase : MonoBehaviour
{
    public bool hasFade = true;
    public CanvasGroup canvasGroup;
    public string uiName;

    protected virtual void Awake()
    {
        canvasGroup = GetComponent<CanvasGroup>();
    }

    public virtual void OnEnter()
    {
        if (hasFade)
        {
            canvasGroup.DOKill();
            canvasGroup.blocksRaycasts = true;
            DOTween.To(() => canvasGroup.alpha, x => canvasGroup.alpha = x, 1, 0.2f);
        }
        else
        {
            this.gameObject.SetActive(true);
        }
    }

    public virtual void OnExit()
    {
        if (hasFade)
        {
            canvasGroup.DOKill();
            canvasGroup.blocksRaycasts = false;
            DOTween.To(() => canvasGroup.alpha, x => canvasGroup.alpha = x, 0, 0.2f);
        }
        else
        {
            this.gameObject.SetActive(false);
        }
    }

    public virtual void OnPause()
    {
        
    }
}
